package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.QuestionsAndAnswers;
import cn.wolfcode.trip.base.query.QuestionsAndAnswersQueryObject;
import cn.wolfcode.trip.base.service.*;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 问达人控制器
 */
@RestController
@RequestMapping("questionsAndAnswers")
public class QuestionsAndAnswersController {
    @Autowired
    private IQuestionsAndAnswersService questionsAndAnswersService;


    /**
     * 查询所的问题
     *
     * @return
     */
    @GetMapping("question")
    public PageInfo query(QuestionsAndAnswersQueryObject qo) {
        return questionsAndAnswersService.query(qo);
    }

    /**
     * 根据id查询问题信息
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public QuestionsAndAnswers getQuestionsAndAnswersById(@PathVariable("id")Long id){
        QuestionsAndAnswers questionsAndAnswers= questionsAndAnswersService.getQuestionsAndAnswersById(id);
        return questionsAndAnswers;
    }

    @PostMapping
    public JSONResult insertQuestions(QuestionsAndAnswers questionsAndAnswers){
        questionsAndAnswersService.saveOrUpdate(questionsAndAnswers);
        return  new JSONResult();
    }
    
}
